#include "processor.h"

trace_queue::trace_queue(unsigned int size) {
	tq = new unsigned int[size];
	this->size = size;
	head = 0;
	tail = 0;
	length = 0;
}


// push a trace index(payload buffer index of first istruction) into the trace queue
void trace_queue::push(unsigned int trace_index, unsigned int trace_length) {
	assert(length < size);

	tq[tail].trace_index = trace_index;
	tq[tail].trace_length = trace_length;
	tail = MOD_S((tail + 1), size);
	length += 1;
}


// pop a trace's index from the trace queue
unsigned int trace_queue::pop_index() {
	assert(length > 0);
	return(tq[head].trace_index);
}


// pop a trace's length from the trace queue
unsigned int trace_queue::pop_length() {
	assert(length > 0);
	return(tq[head].trace_length);
}


// pop an instructions (its payload buffer index) from the trace queue
void trace_queue::pop() {

	assert(length > 0);
	head = MOD_S((head + 1), size);
	length -= 1;

}

// flush the trace queue (make it empty)
void trace_queue::flush() {
	head = 0;
	tail = 0;
	length = 0;
}

bool trace_queue::trace_queue_empty(){
	if(head==tail)
		return true;
	else
		return false;
}
